package kr.hkit.calendarproject12.Fragment;

import java.util.ArrayList;

import kr.hkit.calendarproject12.Detail;
import kr.hkit.calendarproject12.R;
import kr.hkit.calendarproject12.Adapter.ListCalendarAdapter;
import kr.hkit.calendarproject12.DAO.DAO;
import kr.hkit.calendarproject12.DTO.MyItem;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class ListCalendar extends Fragment {
	final static String TAG = "DATE";
	ListCalendarAdapter lcAdapter;
	DAO dao;
	ListView list;
	ArrayList<MyItem> arList;
	MyItem item;
	
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		Log.d(TAG, "onCreateView() - list");
		View root = inflater.inflate(R.layout.schedulelist, container, false);

		dao = DAO.open(getActivity());	
		arList = dao.selectTotalSchedule();
		
		lcAdapter = new ListCalendarAdapter(getActivity(), arList, R.layout.listlayout);
		ListView todayList = (ListView) root.findViewById(R.id.schedule_list1);
		todayList.setAdapter(lcAdapter);
			
		todayList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> adapterView, View clickedView, int pos, long id) {
				Intent intent = new Intent(getActivity(), Detail.class);
				intent.putExtra("ParamTitle", arList.get(pos).getTitle());
				intent.putExtra("ParamStartDate", arList.get(pos).getStartDate());
				intent.putExtra("ParamStartTime", arList.get(pos).getStartTime());
				intent.putExtra("ParamAlarmInterval", arList.get(pos).getAlarmInterval());
				intent.putExtra("ParamMemo", arList.get(pos).getMemo());
				startActivity(intent);
			}
			
		});
		

		return root;
	}

}
